package qunaer;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-14下午 05:07
 */
public class Test2 {

    public int solution(int[] arr) {
        Arrays.sort(arr);
        int[] res = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            res[i] = arr[arr.length - 1 - i];
        }
        int[] sum = new int[res.length];
        sum[0] = res[0];
        for (int i = 1; i < res.length; i++) {
            sum[i] = sum[i - 1] + res[i];
        }
        int res1 = 0;
        for (int i = 0; i < sum.length; i++) {
            if (sum[i] < 0) {
                return res1;
            }
            res1 += sum[i];
        }
        return 0;
    }
}
